<%@ page import="domain.Entreprise" %>
<%@ page import="domain.Contact" %>
<%@ page import="util.ContactsContainer" %>
<%@ page import="util.PhoneKind" %>
<%@ include file="include/header.jsp" %>

<h2 class="center">Update a contact</h2>
<form action="./UpdateContact.htm" method="POST">
	<div class="row-fluid">
		<div class="span6">
			<h3 class="center">Contact informations</h3>
			<input type="hidden" name="idContact" value="${contact.id}">
			<input type="hidden" name="versionContact" value="${contact.version}">
			<table>
				<tr>
					<td align="right">First name (*) : </td>
					<td><input type="text" name="firstName" value="${contact.firstName}" required /></td>
				</tr>
				<tr>
					<td align="right">Last name : </td>
					<td><input type="text" name="lastName" value="${contact.lastName}" /></td>
				</tr>
				<tr>
					<td align="right">Email : </td>
					<td><input type="email" name="emailC" value="${contact.email}"/></td>
				</tr>
				<c:if test="${numEntreprise != null}">
					<tr>
						<td align="right">Siret : </td> 
						<td><input type="number" min="0" step="1" pattern="\d+" name="siret" value="${numEntreprise}"/></td>
					</tr>
				</c:if>
				
			</table>
		</div>
		<div class="span6">
			<h3 class="center">Address</h3>
			<input type="hidden" name="idAddress" value="${contact.address.id}">
			<input type="hidden" name="versionAddress" value="${contact.address.version}">
			<table>
				<tr>
					<td align="right">Street : </td>
					<td><input type="text" name="street" value="${contact.address.street}"/></td>
				</tr>
				<tr>
					<td align="right">City : </td>
					<td><input type="text" name="city" value="${contact.address.city}"/></td>
				</tr>
				<tr>
					<td align="right">Zip code : </td>
					<td><input type="text" name="zip" value="${contact.address.zip}"/></td>
				</tr>
				<tr>
					<td align="right">Country : </td>
					<td><input type="text" name="country" value="${contact.address.country}"/></td>
				</tr>
			</table>
		</div>
	</div>
	<div class="row-fluid">
		<div class="span6">
			<div></div>
			<h3>Phone numbers</h3>
			<c:if test="${contact.phones != null}">
				<c:forEach items="${contact.phones}" var="phone" varStatus="status">
					<input type="hidden" name="idPhone" value="${phone.id}">
					<input type="hidden" name="versionPhone" value="${phone.version}">
					<select name="kindTypes">
						<c:if test="${phone.phoneKind == 'portable'}">
							<option selected>portable</option>
							<option>fixe</option>
							<option>professionnel</option>
						</c:if>
						<c:if test="${phone.phoneKind == 'fixe'}">
							<option>portable</option>
							<option selected>fixe</option>
							<option>professionnel</option>
						</c:if>
						<c:if test="${phone.phoneKind == 'professionnel'}">
							<option>portable</option>
							<option>fixe</option>
							<option selected>professionnel</option>
						</c:if>
					</select>
					<input type="tel" name="phoneNumbers" placeholder="number" value="${phone.phoneNumber}">
	    		</c:forEach>
			</c:if>
			<div id="phoneLine" style="visibility:hidden; height:0">
				<select name="kindTypes">
					<%
					for(PhoneKind kind : PhoneKind.values()) {
						%><option><%=kind %></option><%
					}
					%>
				</select>
				<input type="tel" name="phoneNumbers" placeholder="number" /><br />
			</div>
			<div id="phones"></div>
			<p class="btn btn-primary" onClick="addPhoneNumber()">Add a phone number</p>
		</div>
		<div class="span6">
			<div></div>
			<h3>Groups</h3>
			<c:if test="${groups == null && groupsSelected == null}">
				<p>No groups available</p>
			</c:if>
			<c:if test="${groups != null}">
				<p>Select many groups</p>
				<c:forEach items="${groups}" var="group" varStatus="status">
					<input type="checkbox" value="${group.groupId}" name="groups" /> ${group.groupName}<br />
	    		</c:forEach>
			</c:if>
			<c:if test="${groupsSelected != null}">
				<c:forEach items="${groupsSelected}" var="groupSelected" varStatus="status">
					<input type="checkbox" value="${groupSelected.groupId}" name="groups" checked /> ${groupSelected.groupName}<br />
	    		</c:forEach>
			</c:if>
		</div>
	</div>
	<hr>
	<div class="row-fluid" style="margin-top:10px">
		<input type="submit" class="btn btn-success btn-large" value="Update" />
	</div>
</form>

<%@ include file="include/footer.jsp"%>